选项和自定义
display常用参数:
| 参数 | 描述 |
|---|---|
| display.max_rows | 要显示的最大行数 |
| display.max_columns | 要显示的最大列数 |
| display.max_colwidth | 显示最大列宽 |
| display.precision | 显示十进制数的精度 |
| display.expand_frame_repr | 显示数据帧以拉伸页面 |
get_option()
返回指定输出中的值
print(f'display.max_rows:{pd.get_option("display.max_rows")}') # 输出结果:display.max_rows:60
print(f'display.max_columns:{pd.get_option("display.max_columns")}') # 输出结果 : display.max_columns:20
set_option()
该函数需要两个参数, 并将该值设置为指定的参数值
print(f'display.max_rows:{pd.get_option("display.max_rows")}')
# 输出结果:
# display.max_rows:60
pd.set_option("display.max_rows",500)
print(f'display.max_rows:{pd.get_option("display.max_rows")}')
# 输出结果:
# display.max_rows:500
reset_option()
该函数接收一个参数,并将其设置为默认值
pd.set_option("display.max_rows",500)
print(f'display.max_rows:{pd.get_option("display.max_rows")}')
# 输出结果:
# display.max_rows:500
pd.reset_option('display.max_rows')
print(f'display.max_rows:{pd.get_option("display.max_rows")}')
# 输出结果:
# display.max_rows:60
describe_option()
用于打印参数的描述
pd.describe_option('display.max_rows')
option_context()
用于临时设置语句中的选项,当退出使用块时,选项值将自动回复
with pd.option_context('display.max_rows',50):
print(pd.get_option("display.max_rows"))
# 输出结果: 50